How to understand if (name in {}) in javascript?
Posted
by
tiplip
on Stack Overflow
See other posts from Stack Overflow
or by tiplip
Published on 2010-12-22T12:40:42Z
Indexed on
2010/12/22
12:54 UTC
Read the original article
Hit count: 103
JavaScript
I encounter a js function snippet, list as follows
each = function(obj, fun) {
if (typeof fun != "function") {
return obj
}
if (obj) {
var return_value;
if (obj.length === undefined) {
for (var name in obj) {
if (name in {}) { // how to undertand this line, what's purpose?
continue
}
return_value = fun.call(obj[name], obj[name], name);
if (return_value == "break") {
break
}
}
} else {
for (var i = 0,
length = obj.length; i < length; i++) {
return_value = fun.call(obj[i], obj[i], i);
if (return_value == "break") {
break
}
}
}
}
return obj
};
Thanks for your answer:)
© Stack Overflow or respective owner